
// 处理初始化模版
import React from 'react';

import {
    promptBox
} from 'nc-lightapp-front';

import deepCopy from '../../../../public/functions/deep-copy';

import language from '../../language';


// 初始化处理template数据
export default function processTemplate(template) {
    console.log(template);
    template['ncc60071025list'].items.map((item, index) => {
        // item.width = '120px';
    });

    template['ncc60071025list'].items.push({
        itemtype: 'customer',
        label: language['hi6007-000029'],/* 国际化处理： 操作*/
        visible: true,
        width: '130px',
        fixed: 'right',
        attrcode: 'operation',
        render: (text, record, index) => {
            let isHisPsn = record.values['pk_psndoc.ishiskeypsn'].value;
            let isRootNode = false;

            if(!this.state.currentSelectDepartment) {
                isRootNode = true;
            }

            return (
                <div>
                    <a
                        href="javascript:void(0)"
                        className={`operator-btn ${isHisPsn ? 'disabled' : ''}`}
                        onClick={() => {
                            if(isHisPsn) {
                                return;
                            }
                            this.setState({
                                selectedRows: [{ data: record }],
                                pageFrom : 'modify'
                            }, () => {
                                this.toEditPage('modify');
                            });
                        }}
                    >
                        {language['hi6007-000030']}{/* 国际化处理： 修改*/}
                    </a>
                    <a
                        href="javascript:void(0)"
                        className={`operator-btn ${isRootNode ? 'disabled': ''}`}
                        onClick={() => {
                            if(isRootNode) {
                                return;
                            }
                            this.setState({
                                // 为了和选中的数据对应上
                                selectedRows: [{ data: record }]
                            }, () => {
                                this.deleteMainTableRow();
                            });
                        }}
                    >
                        {language['hi6007-000031']}{/* 国际化处理： 删除*/}
                    </a>
                </div>
            );
        }
    });

    template['gridrelation']['sort'] = {
        destBrowseAreaCode: null,
        destEditAreaCode: null,
        srcAreaCode: 'sort',
        tabRelation: []
    }
    
    template['hi_psnjob_h'].relationcode = 'bd_psndoc';
    template['hi_psnorg_h'].relationcode = 'bd_psndoc';

    template['hi_psnjob_history'] = deepCopy(template.hi_psnjob);
    
    template['createuser'].items.map((item) => {
        item.width = '122px';
    });

    // 隐藏照片
    template['bd_psndoc'].items.map((item) => {
        if(item.attrcode === 'photo') {
            item.visible = false
        }
    });

    // 新增是个参照，后台只给了接口，自己拼一个form
    template['add_refer_form'] = {
        areastatus: "edit",
        code: "add_refer_form",
        moduletype: 'form',
        name: '',
        items: []
    };

    return template
}
